# _*_ coding: utf-8 _*_
"""
Time:     2022/3/11 21:49
Author:   suhong
Version:  V 0.1
File:     login.py
"""
import time

from base.box import Boxdriver, get_driver
from base.public import GetYmalData, GetPath, GetIniDate, GetLogger

yaml_path = GetPath().get_path(r'\elements', 'login_page.yaml')
print(yaml_path)
user_name = GetIniDate().get_init_data("info", "user_name")
password = GetIniDate().get_init_data("info", "password")


class LoginPage(Boxdriver):
    def __init__(self):
        super(LoginPage,self).__init__(get_driver())
        tt = time.strftime("%Y-%m-%d")
        self.logs = GetLogger(GetPath().get_path(r"\results\logger", f'日志{tt}.txt'))
    # def __init__(self):
    #     Boxdriver(get_driver())
    #     tt = time.strftime("%Y-%m-%d")
    #     self.logs = GetLogger(GetPath().get_path(r"\results\logger", f'日志{tt}.txt'))
    @staticmethod
    def get_yaml():
        '''
        读取yaml文件获取一个字典
        :return:
        '''
        data = GetYmalData().get_ymal_data(yaml_path)
        return data

    def go_to_login(self):
        self.basedriver.click(self.get_yaml()["登录"])

    def move(self):
        self.basedriver.max_window()
        self.basedriver.mouse_element(self.get_yaml()["头像"])

    def login(self, username=user_name, password=password):
        self.basedriver.send_key(self.get_yaml()["用户名"], username)
        self.basedriver.send_key(self.get_yaml()["密码"], password)
        self.basedriver.click(self.get_yaml()["登录2"])

    def iframae(self):
        self.basedriver.switch_to_frame(self.get_yaml()["切换"])
    def send_text(self):
        self.basedriver.send_key(self.get_yaml()["输入框"],"张嘉文")
        time.sleep(2)
        self.basedriver.click(self.get_yaml()["百度一下"])
        return self.basedriver._base_driver.title


if __name__ == "__main__":
    # LoginPage().go_to_login()
    # time.sleep(1)
    LoginPage().send_text()
